﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Collections.Generic;
using HZ.DrugTrade.Web;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;

namespace HZ.DrugTrade.Web.Hospitals.Collection
{
    public partial class InvoiceSelect : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetBind();
            }
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            SetBind();
        }

        private void SetBind()
        {
            //只有已通过审核的发票才能显示
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            try
            {
                int totalRecord = 0;
                //HZ.DrugTrade.Model.Query.InvoicePay qryWhere = new HZ.DrugTrade.Model.Query.InvoicePay();
                HZ.DrugTrade.Model.Query.Invoice qryWhere = new HZ.DrugTrade.Model.Query.Invoice();
                qryWhere.CompanyID_PS = Request["CID"].ToString();
                string[] isp = Request["invoiceid"].Split(',');
                if (isp.Length > 1)
                {
                    qryWhere.Append = " InvoiceSerialID in (" + Request["invoiceid"].Substring(0, Request["invoiceid"].Length).ToString() + ") or InvoicePaySerialID IS NULL";
                }
                else
                {
                    qryWhere.Append = " InvoiceSerialID in (" + Request["invoiceid"].ToString() + ") or InvoicePaySerialID IS NULL";
                }
                qryWhere.HospitalID = CurrentAccount.GetUser().Org.OrgID;
                //发票审核状态为1，即通过审核
                qryWhere.AuditStatus=1;
                qryWhere.SortFields = "InvoiceTime desc";
                qryWhere.InvoiceTimeFrom = new HZ.Common.ConvertHelper(this.txtStartDate.Text).ToDateTime;
                qryWhere.InvoiceTimeTo = new HZ.Common.ConvertHelper(this.txtEndDate.Text).ToDateTime;

                IBLL_Purchase iPurchase = Factory.BLL_Purchase();
                IList<HZ.DrugTrade.Model.View.Invoice> lstInvoice = iPurchase.GetInvoiceByCompanyID_PS(qryWhere, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalRecord);
                AspNetPager1.RecordCount = totalRecord;
                gvwDataInfo.AutoGenerateColumns = false;
                this.gvwDataInfo.DataSource = lstInvoice;
                this.gvwDataInfo.DataBind();

            }
            catch (Exception ex)
            {
                PageError(ex.Message, "");
            }

        }


        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }


    }
}
